import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2022-12-26
 * Time: 13:27
 */


public class TestDemo {
    public static boolean isNumber(String str) {
        char[] array = str.toCharArray();
        for (int i = 0; i < array.length; i++) {
            if (array[i] < '0' || array[i] > '9') {
                return false;
            }
        }
        return true;
    }
    public static String fistUpper(String str) {
        if ("".equals(str)||str==null) {
            return str ;
        }
        if (str.length()>1) {
            return str.substring(0, 1).toUpperCase()+str.substring(1) ;
        }
        return str.toUpperCase() ;
    }
    public static void main(String[] args) {
        System.out.println(fistUpper("yuisama"));
        System.out.println(fistUpper(""));
        System.out.println(fistUpper("a"));
    }
    public static void main21(String[] args) {
        System.out.println("hello".isEmpty());
        System.out.println("".isEmpty());
        System.out.println(new String().isEmpty());
    }
    public static void main20(String[] args) {
        String str = " hello%$$%@#$%world 哈哈哈 " ;
        System.out.println(str.length());
    }
    public static void main19(String[] args) {
        String str = " hello%$$%@#$%world 哈哈哈 " ;
        System.out.println(str.toUpperCase());
        System.out.println(str.toLowerCase());
    }
    public static void main18(String[] args) {
        String str = " hello world " ;
        System.out.println("["+str+"]");
        System.out.println("["+str.trim()+"]");
    }
    public static void main17(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.substring(5));
        System.out.println(str.substring(2, 4));
    }
    public static void main16(String[] args) {
        String str = "name=zhangsan&age=18" ;
        String[] result = str.split("&") ;
        for (int i = 0; i < result.length; i++) {
            String[] temp = result[i].split("=") ;
            System.out.println(temp[0]+" = "+temp[1]);
        }
    }
    public static void main15(String[] args) {
        String str = "192.168.1.1" ;
        String[] result = str.split("\\.") ;
        for(String s: result) {
            System.out.println(s);
        }
    }
    public static void main14(String[] args) {
        String str = "hello world hello bit" ;
        String[] result = str.split(" ",2) ;
        for(String s: result) {
            System.out.println(s);
        }
    }
    public static void main13(String[] args) {
        String str = "hello world hello bit" ;
        String[] result = str.split(" ") ; // 按照空格拆分
        for(String s: result) {
            System.out.println(s);
        }
    }
    public static void main12(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.replaceAll("l", "_"));
        System.out.println(str.replaceFirst("l", "_"));
    }
    public static void main11(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.indexOf("world")); // 5,w开始的索引
        System.out.println(str.indexOf("bit")); // -1，没有查到
        if (str.indexOf("hello") != -1) {
            System.out.println("可以查到指定字符串！");
        }
    }
    public static void main10(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.indexOf("l")); // 2
        System.out.println(str.indexOf("l",5)); // 8
        System.out.println(str.lastIndexOf("l")); // 8
    }
    public static void main9(String[] args) {
        String str = "**@@helloworld!!" ;
        System.out.println(str.startsWith("**")); // true
        System.out.println(str.startsWith("@@",2)); // ture
        System.out.println(str.endsWith("!!")); // true
    }
    public static void main8(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.contains("world")); // true
    }
    public static void main7(String[] args) {
        System.out.println("A".compareTo("a")); // -32
        System.out.println("a".compareTo("A")); // 32
        System.out.println("A".compareTo("A")); // 0
        System.out.println("AB".compareTo("AC")); // -1
        System.out.println("刘".compareTo("杨"));
    }
    public static void main6(String[] args) {
        String str1 = "hello" ;
        String str2 = "Hello" ;
        System.out.println(str1.equals(str2)); // false
        System.out.println(str1.equalsIgnoreCase(str2)); // true
    }
    public static void main5(String[] args) throws UnsupportedEncodingException {
        String str = "abcd";
        byte[] bytes = str.getBytes("GBK");
        System.out.println(Arrays.toString(bytes));
    }
    public static void main4(String[] args) {
        String str = "12a34567";
        System.out.println(isNumber(str)? " 字符串由数字所组成！" : "字符串中有非数字成员！");    }
    public static void main3(String[] args) {
        String str = "helloworld" ;
        char[] chars =str.toCharArray();//把str指向的字符串对象变为字符数组
        System.out.println(Arrays.toString(chars));
    }
    public static void main2(String[] args) {
        String str = "hello" ;
        System.out.println(str.charAt(10));
    }
    public static void main1(String[] args) {
        char[] val = {'a','b','c','d','e'};
        String str = new String(val,1,3);
        System.out.println(str);
    }
}
